<!DOCTYPE html>
<html lang='zh-CN'>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
<title>系统公告</title>
<link rel="icon" href="favicon.ico" type="image/ico">
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/materialdesignicons.min.css" rel="stylesheet">
<link href="css/animate.css" rel="stylesheet">
<link href="js/select2/select2.min.css" rel="stylesheet">
<!--日期选择插件-->
<link rel="stylesheet" href="js/bootstrap-datepicker/bootstrap-datepicker3.min.css">
<link href="css/style.min.css" rel="stylesheet">
<link href="js/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
<link href="js/bootstrapvalidator/dist/css/bootstrapValidator.css" rel="stylesheet">
<style>
    .select2-container {
      width: 100%!important;
    }
</style>
</head>
<body>
<div class="container-fluid p-t-15">

  <div class="row">
    <div class="col-lg-12">
      <div class="card">
        <div class="card-header">

          <div id="toolbar" class="toolbar-btn-action">
              <form class="form-inline" method="post" id="searchForm">
                <div class="form-group">
                  <label>公告标题:</label>
                  <input type="text" class="form-control" name="noticeTitle">
                </div>
                <div class="form-group">
                  <button class="btn btn-info btn_query btn-round" type="button" id="searchFormBtn">查询</button>
                </div>
                <div class="form-group">
                  <button class="btn btn-success btn_query btn-round" type="button" id="addBtn">添加</button>
                </div>
                <div class="form-group">
                  <button class="btn btn-warning btn_query btn-round" type="button" id="editBtn">编辑</button>
                </div>
                <div class="form-group">
                  <button class="btn btn-purple btn_query btn-round" type="button" id="fbBtn" onclick="changeStatus(1)">发布</button>
                </div>
                <div class="form-group">
                  <button class="btn btn-pink btn_query btn-round" type="button" id="xjBtn" onclick="changeStatus(2)">下架</button>
                </div>
              </form>
          </div>

        </div>
        <div class="card-body">

          <table id="data_grid"></table>

        </div>
      </div>
    </div>
  </div>

  <div class="modal fade" id="addOrEditModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel">
  <div class="modal-dialog modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <div id="error_tips" style="color: #c9302c"></div>
      </div>
      <div class="modal-body">
        <form id="addOrEditForm" method="post">
          <div class="row">
            <div class="col-xs-6">
              <div class="input-group m-b-10">
                <span class="input-group-addon">公告标题</span>
                <input type="hidden" name="id">
                <input type="text" name="noticeTitle" class="form-control">
              </div>
            </div>
            <div class="col-xs-6">
              <div class="input-group m-b-10">
                <span class="input-group-addon">公告类型</span>
                <select class="form-control" name="noticeType" id="noticeType"></select>
              </div>
            </div>
          </div>
          <div class="row">
            <div class="col-xs-6">
              <div class="input-group m-b-10">
                <span class="input-group-addon" id="basic-dept">公告级别</span>
                <select class="form-control" name="noticeLevel" id="noticeLevel"></select>
              </div>
            </div>
            <div class="col-xs-6">
              <div class="input-group m-b-10">
                <span class="input-group-addon" id="basic-email">发布日期</span>
                <input class="form-control js-datepicker" data-date-format="yyyy-mm-dd" type="text" name="releaseTime"/>
              </div>
            </div>
          </div>
          <div class="row">
            <div class="col-xs-12">
              <div class="input-group m-b-10">
                <textarea id="editor" name="noticeContent"></textarea>
              </div>
            </div>
          </div>
        </form>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
          <button type="button" id="saveFormBtn" class="btn btn-primary">保存</button>
        </div>
      </div>

    </div>
  </div>
</div>


  <script type="text/javascript" src="js/jquery.min.js"></script>
  <script type="text/javascript" src="js/bootstrap.min.js"></script>
  <script type="text/javascript" src="js/bootstrap-table/bootstrap-table.js"></script>
  <script type="text/javascript" src="js/bootstrap-table/bootstrap-table-zh-CN.min.js"></script>
  <script type="text/javascript" src="js/zero2one/zero2one.version.js"></script>
  <script type="text/javascript" src="js/zero2one/zero2one.core.js"></script>
  <!-- bootstrap表单验证插件 -->
  <script type="text/javascript" src="js/bootstrapvalidator/dist/js/bootstrapValidator.js"></script>
  <!-- bootstrap弹出框插件 -->
  <script type="text/javascript" src="js/jquery.bootstrap.min.js"></script>
  <!-- 表单填充插件 -->
  <script type="text/javascript" src="js/jquery-form/jquery.formloader.js"></script>
  <!-- ckeditor富文本插件 -->
  <script src="js/ckeditor/ckeditor.js"></script>
  <script src="js/ckeditor/config.js"></script>
  <!-- select2下拉框插件 -->
  <script src="js/select2/select2.min.js"></script>
  <script src="js/select2/i18n/zh-CN.js"></script>
  <!--日期选择插件-->
  <script src="js/bootstrap-datepicker/bootstrap-datepicker.min.js"></script>
  <script src="js/bootstrap-datepicker/locales/bootstrap-datepicker.zh-CN.min.js"></script>
  <script type="text/javascript" src="js/main.min.js"></script>

  <script type="text/javascript">

      //设置表头
      var columns = [
          {checkbox: true},
          {field: 'id',title: 'ID'},
          {field: 'noticeTitle',title: '公告标题'},
          {field: 'noticeType',visible: false},
          {field: 'type_name',title: '公告类型'},
          {field: 'noticeLevel',visible: false},
          {field: 'notice_content',visible: false},
          {field: 'level_name',title: '公告级别'},
          {field: 'notice_status',title: '公告状态'},
          {field: 'username',title: '发布人'},
          {field: 'releaseTime',title: '发布时间'}
      ];

      //进入主界面加载数据
      zero2one.datagrid("data_grid", "/noticePage",function (params) {
          return $.extend(zero2one.tableInitParam(params), zero2one.form2json("searchForm"));
      }, columns);

      //点击查询按钮重新加载页面数据
      $("#searchFormBtn").click(function () {
          $('#data_grid').bootstrapTable('refresh');
      });

      var ck = CKEDITOR.replace( 'editor' );


      zero2one.requestV("/select2",{codeTable:"sys_p_notice", codeField:"notice_type"},function (data) {
          $("#noticeType").select2({data: data, minimumResultsForSearch: Infinity});
      });
      zero2one.requestV("/select2",{codeTable:"sys_p_notice", codeField:"notice_level"},function (data) {
          $("#noticeLevel").select2({data: data, minimumResultsForSearch: Infinity});
      });

      zero2one.girdClick("data_grid");

      //点击添加按钮弹出模态框
      $("#addBtn").click(function () {
          $("#addOrEditModal").modal("show");
      });

      $("#editBtn").click(function () {
          //获取选中行的数据
          var datas = $('#data_grid').bootstrapTable('getSelections');
          //判断是否选中行数据，如果没有则提示
          if(datas.length == 1){
              //填充表单
              ck.setData(datas[0].notice_content);//ck回显
              $("#noticeType").select2("val", [datas[0].noticeType]);//select2回显
              $("#noticeLevel").select2("val", [datas[0].noticeLevel]);
              $("#addOrEditForm").formloader({data: datas[0]});
          }else{
              $.messager.alert("温馨提示", "请选择一条数据操作");
              return;
          }
          $("#addOrEditModal").modal("show");
      });


      $('#addOrEditForm').bootstrapValidator({
          fields: {
              noticeTitle: {validators: {notEmpty: {message: '公告标题不能为空'}}},
              releaseTime: {validators: {notEmpty: {message: '发布日期不能为空'}}}
          }
      });

      $("#saveFormBtn").click(function () {
          var bv = $('#addOrEditForm').data('bootstrapValidator');
          bv.validate();
          if (bv.isValid()) {
              //获取富文本编辑器的内容,设置到表单组件中
              var data = ck.getData();
              $("#editor").val(data);

              zero2one.request("/addOrEditNotice?f="+new Date().getTime(),$("#addOrEditForm").serialize(),function (data) {
                  window.location.reload();
              });
          }
      });

      function changeStatus(status) {

          //获取选中行的数据
          var datas = $('#data_grid').bootstrapTable('getSelections');
          //判断是否选中行数据，如果没有则提示
          if(datas.length > 0){
              $.messager.confirm("温馨提示", "您确定要改变发布公告状态吗?", function () {
                  zero2one.request("/changeNoticeStatus?f="+new Date().getTime(),{"status" : status,"ids" : zero2one.array2str(datas)},function (data) {
                      window.location.reload();
                  });
              })
          }else{
              $.messager.alert("温馨提示", "请选择一条或多条数据操作");

          }

      }

  </script>
</div>
</body>
</html>